
clear
set more off

/*********************************************************************************
Name: health_worker_controls.do

Data In: [Data/Original/hw_surveys.dta]

Data Out: [Data/Intermediate/hw_controls.dta]

Results Out: []

Purpose of do-file: Creating a database of health-worker-level control variables
*********************************************************************************/

* Setting path directory
cd "${DIRECTORY}"


** Creating control variables from health worker baseline surveys

use "Data/Original/hw_surveys.dta", clear

* Gender
ta b_sex
gen male = (b_sex==1) if b_sex ~= .
label var male "Gender (male)"

* Age
label var b_age "Age"

* Caste
ta b_caste
gen gen_caste = (b_caste == 1) if b_caste ~= .
gen caste_st = (b_caste == 4) if b_caste ~= .

* Religion
ta b_religion
gen hindu=. 
replace hindu=1 if b_religion==1
replace hindu=0 if b_religion!=1 & b_religion!=. 
label var hindu "Religion (Hindu)"

gen religion_oth = (b_religion < 0 | b_religion > 2) if b_religion ~= .

* Highest education level achieved
ta b_highest_edu
gen b_highest_edu_v2 = b_highest_edu
replace b_highest_edu_v2= b_current_degree-1 if b_current_degree==2|b_current_degree==3|b_current_degree==4|b_current_degree==7|b_current_degree==8|b_current_degree==9
replace b_highest_edu_v2= b_current_degree-2 if b_current_degree==6
replace b_highest_edu_v2= 9 if b_current_degree_oth==22
replace b_highest_edu_v2= 4 if b_current_degree_oth==19
replace b_highest_edu_v2=. if b_highest_edu_v2==-555|b_highest_edu_v2==-111

tab b_highest_edu_v2, gen(edu)
gen otherdip_nonform=edu1+edu10
label var otherdip_nonform "Other diploma/non-formal"
gen twelveandbelow=edu2+edu3+edu4+edu5
label var twelveandbelow "Twelve and below"
gen tertiary=edu6+edu7+edu8+edu9
label var tertiary "Under three years of university"

drop edu1 - edu10

* Job experience before Operation ASHA
label var b_jobs_bef_oa "Any previous work experience" 

* Household size
ta b_live_alone b_hh_size
gen hhd_size = b_hh_size + 1 if b_hh_size > 0
replace hhd_size = 1 if b_live_alone == 1

* Lives in the same neighbourhood as at least one center
gen same_nbhd = .
replace same_nbhd = 1 if (b_center1_same_nbhd==1 | b_center2_same_nbhd==1)
replace same_nbhd = 0 if (b_center1_same_nbhd == 0) & (b_center2_same_nbhd == 0 | b_center2_same_nbhd == -555)

* Owns their house
gen ownhouse=0
replace ownhouse = 1 if b_own_house == 1
label var ownhouse "Owns house"


** Keeping only relevant variables

keep Unique_ID male b_age gen_caste caste_st hindu religion_oth twelveandbelow tertiary b_jobs_bef_oa hhd_size same_nbhd ownhouse

foreach var of varlist male-ownhouse b_age b_jobs_bef_oa {
rename `var' `var'_couns
}


** Replacing by 0's when missing, and creating dummies indicating this

foreach var in b_age b_jobs_bef_oa male gen_caste caste_st hindu religion_oth twelveandbelow tertiary hhd_size same_nbhd ownhouse{
gen `var'_dum_couns = (`var'_couns == .)
replace `var'_couns = 0 if `var'_couns == .
}

save "Data/Intermediate/hw_controls.dta", replace
